package com.example.toolsdemo.handler;

import com.example.toolsdemo.common.ServerResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @author danyubin
 */
@RestControllerAdvice
public class CustomExceptionHandler {

    /**
     * 上传文件超过500k，捕获异常：MaxUploadSizeExceededException
     * @param ex 文件上传相关异常
     * @return 统一响应
     */
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public ServerResponse handlerMaxUploadFile(MaxUploadSizeExceededException ex) {
        return ServerResponse.error("文件上传大小不能超过500k，请压缩图片或者降低图片质量再上传！");
    }
}
